package com.daqian.chance.example.admin.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.daqian.chance.example.admin.modules.system.mapper.SysUserMapper;
import com.daqian.chance.example.admin.modules.system.po.dto.SysUserDTO;
import com.daqian.chance.example.admin.modules.system.po.entity.SysUser;
import com.daqian.chance.example.admin.modules.system.service.ISysUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统-用户 服务实现类
 * </p>
 * @author daqian
 * @since 2019-08-08
 */
@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
    @Override
    public PageInfo<SysUser> page(SysUserDTO sysUserDTO) {
        // 开启分页
        PageHelper.startPage(sysUserDTO.getPageNum(), sysUserDTO.getPageSize());
        List<SysUser> sysUserList = super.list(null);
        // 清除分页
        PageHelper.clearPage();
        return new PageInfo<>(sysUserList);
    }

    /**
     * 根据用户名查询用户
     * @param userName
     * @return
     */
    @Override
    public SysUser selectUserByUserName(String userName) {
        return this.getOne(new QueryWrapper<SysUser>().eq("userName", userName));
    }
}
